package com.pandora.credit.service.impl;

import com.pandora.common.util.Constants;
import com.pandora.credit.dao.MetaDataDao;
import com.pandora.credit.dto.response.AboutResponse;
import com.pandora.credit.entity.MetaData;
import com.pandora.credit.service.MetaDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author developer
 */
@Service
public class MetaDataServiceImpl implements MetaDataService {
    @Autowired
    private MetaDataDao metaDataDao;

    @Override
    @Cacheable(value = "metaData")
    public String getByType(int type) {
        MetaData md = metaDataDao.queryByType(type);
        if (md == null) {
            return null;
        } else {
            return md.getValue();
        }
    }

    @Override
    public AboutResponse doGetAbout() {
        String aboutUrl = getByType(Constants.META_DATA_TYPE_ABOUT);
        String agreementUrl = getByType(Constants.META_DATA_TYPE_AGREE);

        return new AboutResponse(Constants.RETURN_TYPE_ABOUT,
                aboutUrl,
                agreementUrl);
    }
}
